//
//  HomeForwardView.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/27.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class HomeForwardView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private var pic_cons:Constraint?
    var model:HomeStatusViewModel?{
        didSet{
            print(model?.statusModel?.retweeted_status?.pic_urls?.count)
            contentL.text = model?.retweeted_status_content
            
            self.pic_cons?.uninstall()
            //判断是否显示配图
            if (model?.statusModel?.retweeted_status?.pic_urls?.count)! > 0{
                
                self.snp_updateConstraints(closure: { (make) in
                    self.pic_cons = make.bottom.equalTo(picV).offset(10).constraint
                })
                
                picV.isHidden = false
                
                picV.url_pics = model?.statusModel?.retweeted_status?.pic_urls
                
            }
            else
            {
                self.snp_updateConstraints(closure: { (make) in
                    self.pic_cons = make.bottom.equalTo(contentL).offset(10).constraint
                })
                
                picV.isHidden = true
            }

        }
    }
    
    private func setupUI(){
        self.backgroundColor = UIColor(white: 237/256, alpha: 1.0)
        
        addSubview(contentL)
        addSubview(picV)
        contentL.snp_makeConstraints { (make) in
            
            make.left.top.equalTo(self).offset(10)
            
            make.right.equalTo(self).offset(-10)
        }
        
        picV.snp_makeConstraints { (make) in
            make.top.equalTo(contentL.snp_bottom).offset(10)
            
            make.left.equalTo(contentL)
        }
        
        self.snp_makeConstraints { (make) in
           self.pic_cons = make.bottom.equalTo(picV).offset(10).constraint
        }
        
    }
    
    private lazy var contentL = { () -> UILabel in 
        let l = UILabel(text: "", textColor: UIColor.blue, fontSize: BQNormalFontSize)
        
        l.numberOfLines = 0
        
        return l
        
    }()
    private lazy var picV:PicCollectionView = {
        let view = PicCollectionView()
        
        view.backgroundColor = self.backgroundColor
        return view
    }()
}
